find_package(Qt5 COMPONENTS Widgets)

set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)

add_compile_definitions(QT_DLL)

if(ANDROID)
    add_library(test_http SHARED)
elseif(WIN32 AND CMAKE_BUILD_TYPE MATCHES "Release")
    add_executable(test_http WIN32)
else()
    add_executable(test_http)
endif()

# 获取所有源文件
all_source_recurse(cpp_src)

# 获取所有 .ui 文件
qt_all_source_recurse(ui_src)

print_files(ui_src)

# 处理 .qrc 资源文件，生成对应 .cpp 代码文件
qt5_add_resources(qrc_FILES
    ${CMAKE_SOURCE_DIR}/static/resource/resource.qrc
    ${CMAKE_SOURCE_DIR}/static/css/css.qrc
)


target_include_directories(test_http
    PRIVATE
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/client
    ${CMAKE_CURRENT_SOURCE_DIR}/tools
    ${CMAKE_CURRENT_SOURCE_DIR}/tools/module
    ${CMAKE_CURRENT_SOURCE_DIR}/forms
)


target_sources(test_http
    PRIVATE
    ${cpp_src}
    ${qrc_FILES}
    ${ui_src}
)

target_link_libraries(test_http
    PRIVATE 
    qt5
    common
    tools
    openssl
    protobuf
    proto_packge
)


# 在生成后处理Windeployqt，用于处理图标资源
if(WIN32)
    add_custom_command(TARGET test_http POST_BUILD
        COMMAND ${CMAKE_COMMAND} -E copy_if_different
            $<TARGET_FILE:test_http>
            $<TARGET_FILE_DIR:test_http>
    )
    add_custom_command(TARGET test_http POST_BUILD
        COMMAND ${Qt_PATH}/bin/windeployqt.exe --no-translations --no-quick-import --no-angle --no-opengl-sw
            $<TARGET_FILE_DIR:test_http>
    )
    
    # 把 dll 目录下的所有文件复制到安装目录下
    # add_custom_command(TARGET test_http POST_BUILD
    # COMMAND ${CMAKE_COMMAND} -E copy_directory
    # ${CMAKE_SOURCE_DIR}/dll
    # $<TARGET_FILE_DIR:test_http>
    # )

endif()
